<template>
  <div class="visitList">
    <soltTitle>
      <van-search
        v-model="value"
        shape="round"
        show-action
        placeholder="请输入关键联系人"
        readonly
        @click="skipQuery"
      >
        <template #action>
          <div @click="skipQuery" style="color:#1989fa">搜索</div>
        </template>
      </van-search>
    </soltTitle>
    <ul>
      <li v-for="item in arr" @click="SkipAdd(item.id,item.custName)">
        <van-cell is-link class="visitListLi">
          <van-image round width="2.5rem" height="2.5rem" src="https://img.yzcdn.cn/vant/cat.jpeg" />
          <span>{{item.custName}}</span>
        </van-cell>
      </li>
    </ul>
  </div>
</template>

<script>
import soltTitle from "../../components/soltTitle";
import { GetCustDateAPI } from "../..//request/api";

export default {
  data() {
    return {
      arr: [],
      value: ""
    };
  },
  methods: {
    SkipAdd(cusId, cusName) {
      this.$router.push({
        path: "/visitadd",
        query: { id: cusId, name: cusName }
      });
    },
    skipQuery() {
      this.$store.state.lastRouter = false;
      this.$router.push("/visitquery");
    }
  },
  components: {
    soltTitle
  },
  created() {
    console.log(this.$store.state.arr);
    if (this.$store.state.arr.length == 0) {
      GetCustDateAPI().then(res => {
        if (res.errCode == 0) {
          this.arr = res.data.records;
        }
      });
    }else{
      this.arr = this.$store.state.arr
    }
  }
};
</script>

<style scoped>
.visitList ul {
  margin-top: 10px;
}

.van-cell span {
  margin-left: 10px;
}

.van-cell__value--alone {
  display: flex;
  align-items: center;
}
</style>